/** 
  实习评价模板设置
*/
<template>
  <div class="intern-eval-temp-set-container">
    <condition-card @reset="reset" @search="onSubmit" label-position="right" label-width="150px">
      <el-row :gutter="24" style="height: 50px;">
        <el-col :span="8">
          <el-form-item :label="$t('internEvaluateTempSet.evaluateTempName')">
            <el-input v-model="queryForm.condition.templateName" clearable :maxlength="64" style="width: 100%"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('graduateBase.trainingLevel')">
            <el-select v-model="queryForm.condition.trainingLevelList" multiple clearable style="width: 100%">
              <el-option
                v-for="item in options.trainingLevelList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('graduateBase.cultivationCategory')">
            <el-select v-model="queryForm.condition.trainingTypeList" multiple clearable style="width: 100%">
              <el-option
                v-for="item in options.trainingTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24" style="height: 50px;">
        <el-col :span="8">
          <el-form-item :label="$t('graduateBase.waysOfLearning')">
            <el-select v-model="queryForm.condition.learnFormList" multiple clearable style="width: 100%">
              <el-option
                v-for="item in options.learnFormList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('graduateBase.college')">
            <el-select v-model.trim="queryForm.condition.collegeAcademyList" filterable @change="changeCollege" clearable style="width: 100%">
              <el-option
                v-for="item in options.collegeAcademyList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="$t('graduateBase.profession')">
            <el-select v-model="queryForm.condition.majorList" multiple filterable clearable style="width: 100%">
              <el-option
                v-for="item in options.majorList"
                :key="item.code"
                :label="item.name"
                :value="item.code">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24" style="height: 50px;margin-left: -13px!important;">
        <el-col :span="8">
          <el-form-item :label="$t('templateSetting.isEnabled')">
            <el-select v-model="queryForm.condition.isEnabled" clearable style="width: 100%">
              <el-option
                v-for="item in options.isEnabled"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </condition-card>
    <el-card shadow="never" v-loading="loading" body-style="padding: 24px;" class="card-margin">
      <h1 class="condition-title">{{ $t('internEvaluateTempSet.internEvaluateTempSetTable') }}</h1>
      <div class="edu-opertion-bar sub-title">
        <div class="float-right" style="display: flex;">
          <el-button v-if="permitToExport" type="primary" @click="exportTemplate">{{$t('common.btn.export')}}</el-button>
          <el-button v-if="permitToAdd" @click="addInternEvaluate">{{ $t('common.btn.add') }}</el-button>
        </div>
      </div>
      <edu-table :pagination="false" :order='false' :tooltipEffect="tooltipEffect" stripe :data="dataList" size="mini" @selection-change="handleSelectionChange">
        <edu-table-column :label="$t('internEvaluateTempSet.evaluateTempName')" prop="templateName"></edu-table-column>
        <edu-table-column :label="$t('templateSetting.description')" prop="description"></edu-table-column>
        <edu-table-column :label="$t('graduateBase.trainingLevel')" prop="trainingLevelStr"></edu-table-column>
        <edu-table-column :label="$t('graduateBase.cultivationCategory')" prop="trainingTypeStr"></edu-table-column>
        <edu-table-column :label="$t('graduateBase.degreeType')" prop="degreeTypeStr"></edu-table-column>
        <edu-table-column :label="$t('graduateBase.waysOfLearning')" prop="learnFormStr"></edu-table-column>
        <edu-table-column :label="$t('graduateBase.college')" prop="collegeAcademyStr"></edu-table-column>
        <edu-table-column :label="$t('graduateBase.profession')" prop="majorStr"></edu-table-column>
        <edu-table-column :label="$t('templateSetting.isEnabled')" prop="isEnabled">
          <template slot-scope="scope">
            <div class="is-enabled-container">
              <el-button v-if="scope.row.isEnabled === 0" type="danger" plain>{{ scope.row.isEnabled | isEnabled }}</el-button>
              <el-button v-else type="success" plain>{{ scope.row.isEnabled | isEnabled }}</el-button>
            </div>
          </template>  
        </edu-table-column>
        <edu-table-column :label="$t('common.text.operation')" fit prop="operate" width="200">
          <template slot-scope="props">
            <el-button v-if="permitToEdit" type="text" @click="editInternEval(props.row)">{{$t('common.btn.edit')}}</el-button>
            <el-button v-if="permitToDetail" type="text" @click="selectDetails(props.row)">{{$t('graduate.details')}}</el-button>
            <el-button v-if="permitToSelectTable" type="text" @click="selectEvalIndexTable(props.row)">{{$t('internEvaluateTempSet.viewEvalIndexTable')}}</el-button>
          </template>
        </edu-table-column>
      </edu-table>
      <el-row type="flex" class="row-bg" justify="end">
        <el-col>
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryForm.pageNum_"
              :page-sizes="[20, 40, 80, 100]"
              :page-size="queryForm.pageSize_"
              layout="total, sizes, prev, pager, next, jumper"
              :total="queryForm.total_"
              style="float:right;margin-top:10px"
            ></el-pagination>
        </el-col>
      </el-row>
    </el-card>
    <edu-export-dialog
      :disabled="exportButton"
      :title="$t('message.prompt')"
      ref="downloadRef"
      :data="exportResult">
    </edu-export-dialog>
    <el-dialog
      :before-close="beforeClose"
      @close="closeDialog"
      :title="title"
      width="50%"
      class="template-setting-dialog"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-form :model="dialogForm" label-position="right" ref="dialogForm" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item
              :label="$t('internEvaluateTempSet.evaluateTempName') + ':'"
              prop="templateName"
              :rules="[{ required: true, message: $t('internEvaluateTempSet.requireEvaluateTempName'), trigger: 'blur' }, { validator: this.checkSpecial, trigger: 'blur'}]">
              <el-input :disabled="dialogMode === 'details'" :maxlength="64" :placeholder="$t('common.pla.pleaseInput')" v-model="dialogForm.templateName" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item 
              :label="$t('graduateBase.trainingLevel') + ':'"
              prop="trainingLevelList">
              <template v-if="dialogMode === 'details' || dialogMode === 'edit' && dialogForm.trainingLevelList === ['全部']">
                <el-select :disabled="dialogMode === 'details'" multiple v-model="dialogForm.trainingLevelList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                  <el-option
                    label="全部"
                    value="全部">
                  </el-option>
                </el-select>
              </template>
              <template v-if="dialogForm.trainingLevelList !== ['全部']">
                <el-select :disabled="dialogMode === 'details'" multiple v-model="dialogForm.trainingLevelList" @change="changeTrainingLevelList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                  <el-option
                    v-for="item in options.trainingLevelList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </template>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item 
              :label="$t('graduateBase.cultivationCategory') + ':'"
              prop="trainingTypeList">
              <template v-if="dialogMode === 'details' || dialogMode === 'edit' && dialogForm.trainingTypeList === ['全部']">
                <el-select :disabled="dialogMode === 'details'" multiple v-model="dialogForm.trainingTypeList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                  <el-option
                    label="全部"
                    value="全部">
                  </el-option>
                </el-select>
              </template>
              <template v-if="dialogForm.trainingTypeList !== ['全部']">
                <el-select :disabled="dialogMode === 'details'" multiple v-model="dialogForm.trainingTypeList" @change="changeTrainingTypeList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                  <el-option
                    v-for="item in options.trainingTypeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item 
              :label="$t('graduateBase.degreeType') + ':'"
              prop="degreeTypeList">
              <el-select disabled multiple v-model="dialogForm.degreeTypeList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                <el-option
                  v-for="item in options.degreeTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item 
              :label="$t('graduateBase.waysOfLearning') + ':'"
              prop="learnFormList">
              <template v-if="dialogMode === 'details' || dialogMode === 'edit' && dialogForm.learnFormList === ['全部']">
                <el-select :disabled="dialogMode === 'details'" multiple v-model="dialogForm.learnFormList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                  <el-option
                    label="全部"
                    value="全部">
                  </el-option>
                </el-select>
              </template>
              <template v-if="dialogForm.learnFormList !== ['全部']">
                <el-select :disabled="dialogMode === 'details'" multiple v-model="dialogForm.learnFormList" @change="changeLearnFormList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                  <el-option
                    v-for="item in options.learnFormList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item 
              :label="$t('graduateBase.college') + ':'"
              prop="collegeAcademyList"
              :rules="[{ required: true, message: $t('graduateBase.requireCollege'), trigger: 'change' }]">
              <el-select :disabled="dialogMode === 'details'" filterable v-model="dialogForm.collegeAcademyList" @change="changeDialogCollege" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                <el-option
                  v-for="item in options.collegeAcademyList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item 
              :label="$t('graduateBase.profession') + ':'"
              prop="majorList">
              <template v-if="dialogMode === 'details' || dialogMode === 'edit' && dialogForm.majorList === ['全部']">
                <el-select :disabled="dialogMode === 'details'" multiple v-model="dialogForm.majorList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                  <el-option
                    label="全部"
                    value="全部">
                  </el-option>
                </el-select>
              </template>
              <template v-if="dialogForm.majorList !== ['全部']">
                <el-select :disabled="dialogMode === 'details'" filterable multiple v-model="dialogForm.majorList" @change="changeMajorList" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                  <el-option
                    v-for="item in options.profession"
                    :key="item.code"
                    :label="item.name"
                    :value="item.code">
                  </el-option>
                </el-select>
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item 
              :label="$t('templateSetting.isEnabled') + ':'"
              prop="isEnabled"
              :rules="[{ required: true, message: $t('templateSetting.requireIsEnabled'), trigger: 'change' }]">
              <el-select :disabled="dialogMode === 'details'" v-model="dialogForm.isEnabled" :placeholder="$t('common.pla.pleaseSelect')" clearable>
                <el-option
                  v-for="item in options.isEnabled"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$t('templateSetting.description') + ':'" prop="description" :rules="[{ validator: checkSpecial, trigger: 'blur'}]">
              <el-input
                :disabled="dialogMode === 'details'"
                type="textarea"
                :rows="5"
                :maxlength="512"
                :placeholder="$t('common.pla.pleaseInput')"
                v-model="dialogForm.description">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-dialog
        width="25%"
        ref="innerDialog"
        :title="$t('graduateBase.prompt')"
        :visible.sync="innerVisible"
        append-to-body
        :top="'28vh'">
        <div style="text-align: left;margin-bottom: 25px;">{{$t('graduateBase.cancelTip')}}</div>
        <div style="text-align: right;">
          <el-button type="primary" @click="confirmInner('innerDialog')">{{$t('common.btn.confirm')}}</el-button>
          <el-button @click="cancelInner('innerDialog')">{{$t('common.btn.cancel')}}</el-button>
          <el-button type="primary" @click="confirmAndClose('dialogForm')">{{$t('graduateBase.saveAndClose')}}</el-button>
        </div>
      </el-dialog>
      <span slot="footer" class="dialog-footer">
        <template v-if="dialogMode === 'add' || dialogMode === 'edit'">
          <el-button @click="cancel('dialogForm')">{{$t('common.btn.cancel')}}</el-button>
          <el-button type="primary" @click="save('dialogForm')">{{$t('common.btn.confirm')}}</el-button>
        </template>
        <template v-else-if="dialogMode === 'details'">
          <el-button @click="closeDialog('dialogForm')">{{$t('common.btn.close')}}</el-button>
        </template>
      </span>
    </el-dialog>
    <el-dialog
      @close="dataListProp={}"
      :title="$t('internEvaluateTempSet.internEvalTempMaintain')"
      width="80%"
      :visible.sync="tableFlag">
      <index-table
        :indexMode="indexMode"  
        :dataListProp="dataListProp"  
        :showFlag="tableFlag"
        @close="(flag) => { tableFlag = flag }">
      </index-table>
    </el-dialog>
  </div>
</template>
<script>
import UTILS from "common/src/utils/utils";
import innovativeApi from 'common/src/api/innovative/innovative';
import { queryDic } from "common/src/api/dictionary";
import graduateStudentApi from 'common/src/api/graduateStudent/graduateStudent';
import indexTable from './indexTable';
export default {
  components: {
    'index-table': indexTable
  },
  data () {
    return {
      auths: [],
      permitToAdd: false,
      permitToEdit: false,
      permitToDetail: false,
      permitToSelectTable: false,
      permitToExport: false,
      userInfo: {},
      allCollege: [],
      currentManageCollege: [],
      exportButton: false,
      exportResult: null,
      queryForm: {
        pageNum_: 1,
        pageSize_: 20,
        total_: 0,
        condition: {
          templateName: '',
          trainingLevelList: [],
          trainingTypeList: [],
          degreeTypeList: ['2'],
          learnFormList: [],
          collegeAcademyList: [],
          majorList: [],
          isEnabled: ''
        }
      },
      dataList: [],
      multipleSelection: [],
      options: {
        trainingLevelList: [],
        trainingTypeList: [],
        degreeTypeList: [],
        learnFormList: [],
        collegeAcademyList: [],
        profession: [],
        majorList: [],
        isEnabled: [{
          label: '停用',
          value: 0
        },
        {
          label: '启用',
          value: 1
        }]
      },
      title: '',
      dialogMode: 'add',
      dialogVisible: false,
      innerVisible: false,
      dialogForm: {
        "templateName": "",
        "trainingLevel": "",
        "trainingLevelList": [],
        "trainingType": "",
        "trainingTypeList": [],
        "degreeType": "",
        "degreeTypeList": [],
        "learnForm": "",
        "learnFormList": [],
        "collegeAcademy": "",
        "collegeAcademyList": "",
        "major": "",
        "majorList": [],
        "isEnabled": '',
        "description": ""
      },
      assessIndexDetVisible: false,
      currentAssessIndex: {},
      editModel: false,
      indexKey: '1', // 面包屑
      dataListProp: {},
      tableFlag: false,
      indexMode: '',
      editModeInfo: {}
    }
  },
  filters: {
    isEnabled(val) {
      switch (val) {
        case 0:
          return '停用'
        case 1:
          return '启用'
        default:
          return val
      }
    }
  },
  async created() {
    // 获取当前用户auths权限
    if (localStorage.getItem("sessiondata")) {
      if (JSON.parse(localStorage.getItem("sessiondata")).auths) {
        this.auths = JSON.parse(localStorage.getItem("sessiondata")).auths;
      }
    }
    // 获取字典
    this.initOptions();
    this.dialogForm.degreeTypeList = ["2"];
    // 获取学院innerRoles为1--管理员，innerRoles为2--教务员
    // 登录用户如果是学院教务员，就获取当前用户的管理学院或者所属学院,innerRoles为1
    // 登录用户如果是学校管理员，就获取字典接口（所有学院）
    // 登录用户如果是学院管理员又是学院教务员，就获取字典接口（所有学院）
    this.userInfo = JSON.parse(localStorage.getItem("user"));
    // 获取所有学院
    await this.getAllCollege();
    // this.userInfo.innerRoles = ['2'];
    if ((this.userInfo.innerRoles.indexOf('1') > -1 && this.userInfo.innerRoles.indexOf('2') > -1) || this.userInfo.innerRoles.indexOf('1') > -1) {
      this.options.collegeAcademyList = this.allCollege;
    } else if (this.userInfo.innerRoles.indexOf('2') > -1) {
      this.options.collegeAcademyList = [{
        value: this.userInfo.faculty,
        label: this.userInfo.facultyName
      }];
      if (this.userInfo.manageFaculty) {
        this.currentManageCollege = this.userInfo.manageFaculty.split(',');
        let manageFaculty = [];
        this.allCollege.map((item) => {
          this.currentManageCollege.map((element) => {
            if (item.value === element) {
              manageFaculty.push({
                value: item.value,
                label: item.label
              });
            }
          });
        });
        if (manageFaculty.length > 0) {
          this.options.collegeAcademyList = this.options.collegeAcademyList.concat(manageFaculty);
        }
      }
    }
    this.getListData();
  },
  methods: {
    async initOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: [
          "X_PYCC", // 培养层次
          "X_PYLB", // 培养类别
          "X_XWLX", // 学位类型
          "X_XXXS", // 学习形式
          "X_YX" // 学院
        ]
      };
      await queryDic(data).then(res => {
        UTILS.fillSelect(
          {
            trainingLevelList: "X_PYCC", // 培养层次
            trainingTypeList: "X_PYLB", // 培养类别
            degreeTypeList: "X_XWLX", // 学位类型
            learnFormList: "X_XXXS" // 学习形式
          },
          res.data,
          this.options
        );
      });
      // graduateStudentApi.getMajorByCollage([]).then(res => {
      //   if (res.code === 200) {
      //     if (Array.isArray(res.data) && res.data.length > 0) {
      //       res.data.map(item => {
      //         this.options.majorList.push({
      //           code: item.code,
      //           name: item.name
      //         });
      //       });
      //       this.options.profession = this.options.majorList;
      //     }
      //   }
      // });
    },
    // 获取学院
    async getAllCollege() {
      await innovativeApi.getAllFaculty().then(res => {
        if (res.code === 200) {
          if (Array.isArray(res.data) &&  res.data.length > 0) {
            res.data.map(item => {
              this.allCollege.push({
                label: (this.$store.getters.language === 'cn' || !this.$store.getters.language) ? item.deptName : item.deptNameEn,
                value: item.deptCode
              });
            });
          }
        }
      });
    },
    // 校验特殊字符$
    checkSpecial(rule, value, callback) {
      let regEn = /[`$]/im;
      if (regEn.test(value)) {
        callback(new Error(this.$t('graduateBase.specialText')))
      } else {
        callback();
      }
    },
    // 修改学院
    changeCollege(val) {
      this.options.majorList = [];
      this.queryForm.condition.majorList = [];
      let parmas = [];
      if (val) {
        parmas = [val];
      }
      graduateStudentApi.getMajorByCollage(parmas).then(res => {
        if (res.code === 200) {
          if (Array.isArray(res.data) && res.data.length > 0) {
            this.options.majorList = val ? res.data : [];
          }
        }
      });
    },
    // 修改培养层次
    changeTrainingLevelList(val) {
      if (val[0] && val[0] === '全部') {
        this.dialogForm.trainingLevelList.splice(0, 1)
      }
    },
    // 修改培养类别
    changeTrainingTypeList(val) {
      if (val[0] && val[0] === '全部') {
        this.dialogForm.trainingTypeList.splice(0, 1)
      }
    },
    // 修改学习形式
    changeLearnFormList(val) {
      if (val[0] && val[0] === '全部') {
        this.dialogForm.learnFormList.splice(0, 1)
      }
    },
    // 修改专业
    changeMajorList(val) {
      if (val[0] && val[0] === '全部') {
        this.dialogForm.majorList.splice(0, 1)
      }
    },
    // 轮询直到获取key值的接口返回
    cycleToGetKey() {
      setTimeout(() => {
        let currentIds = [];
        if (this.multipleSelection.length > 0) {
          this.multipleSelection.forEach((element) => {
            currentIds.push(element.id);
          });
        }
        graduateStudentApi.exportInternEvalInfo({
          "trainingLevelList": this.queryForm.condition.trainingLevelList,
          "trainingTypeList": this.queryForm.condition.trainingTypeList,
          "degreeTypeList": this.queryForm.condition.degreeTypeList,
          "learnFormList": this.queryForm.condition.learnFormList,
          "collegeAcademyList": !this.queryForm.condition.collegeAcademyList ? [] : [this.queryForm.condition.collegeAcademyList],
          "majorList": this.queryForm.condition.majorList,
          "selectRowIds": currentIds
        }).then(res => {
          if (res.success) {
            this.$refs.downloadRef.close();
            this.exportButton = false;
            this.normalDelayRequest(res.key, res.msg);
          } else {
            this.cycleToGetKey();
          }
        });
      }, 3000);
    },
    // 导出异步
    delayRequest(key, name) {
      setTimeout(() => {
        graduateStudentApi.downloadGetKey(key, name).then(res => {
          this.exportResult = res.data;
          if (res.code == 200 && res.data.status) {
            this.exportButton = false;
            let path =
              '/api/practiceservice/export/file?path=' +
              res.data.path + '&name=' + name;
            // window.open(path);
            window.location.href = path;
            this.$message.success(this.$t('result.exportSuccessfully'));
            this.$refs.downloadRef.close();
          } else {
            this.delayRequest(key, name);
          }
        });
      }, 3000);
    },
    // Normal导出异步
    normalDelayRequest(key, name) {
      setTimeout(() => {
        graduateStudentApi.downloadGetKey(key).then(res => {
          this.exportResult = res.data;
          if (res.code == 200 && res.data.status) {
            this.exportButton = false;
            let path =
              '/api/practiceservice/export/file?path=' +
              res.data.path + '&name=' + name;
            // window.open(path);
            window.location.href = path;
            this.$message.success(this.$t('result.exportSuccessfully'));
            this.$refs.downloadRef.close();
          } else {
            this.delayRequest(key, name);
          }
        });
      }, 3000);
    },
    // 导出模板
    exportTemplate() {
      // 1、第一步：调该接口，获取key值以及msg中的文件名
      // 2、第二步：将key值放入接口传参
      // 3、第三步：传入path值以及name(msg中的文件名)值，下载文件
      this.exportResult = null;
      this.$refs.downloadRef.open();
      this.exportButton = true;
      this.cycleToGetKey();
    },
    
    // 保存
    save(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let currentDialogForm = JSON.parse(JSON.stringify(this.dialogForm));
          for (let item in currentDialogForm) {
            if (currentDialogForm.trainingLevelList[0] === '全部') {
              currentDialogForm.trainingLevelList = []
            }
            if (currentDialogForm.trainingTypeList[0] === '全部') {
              currentDialogForm.trainingTypeList = []
            }
            if (currentDialogForm.learnFormList[0] === '全部') {
              currentDialogForm.learnFormList = []
            }
            if (currentDialogForm.majorList == undefined || currentDialogForm.majorList.length <= 0 || currentDialogForm.majorList[0] === '全部' ) {
              currentDialogForm.majorList = []
            }
          }
          currentDialogForm.trainingLevel = currentDialogForm.trainingLevelList.join(',');
          currentDialogForm.trainingType = currentDialogForm.trainingTypeList.join(',');
          currentDialogForm.degreeType = currentDialogForm.degreeTypeList.join(',');
          currentDialogForm.learnForm = currentDialogForm.learnFormList.join(',');
          currentDialogForm.collegeAcademy = currentDialogForm.collegeAcademyList;
          currentDialogForm.collegeAcademyList = !currentDialogForm.collegeAcademyList ? [] : [currentDialogForm.collegeAcademyList];
          currentDialogForm.major = (Array.isArray(currentDialogForm.majorList) && currentDialogForm.majorList.length > 0) ?  currentDialogForm.majorList.join(',') : '';
          if (this.dialogMode === 'add') {
            if (currentDialogForm.hasOwnProperty('id')) {
              delete currentDialogForm.id;
            }
            if (currentDialogForm.hasOwnProperty('oldTemplateName')) {
              delete currentDialogForm.oldTemplateName;
            }
            graduateStudentApi.addInternEvalInfo(currentDialogForm).then(res => {
              this.$message({
                type: "success",
                message: this.$t('common.tips.addSuccess')
              });
              this.dialogVisible = false;
              this.onSubmit();
            });
          } else if (this.dialogMode === 'edit') {
            graduateStudentApi.updateInternEvalInfo(currentDialogForm).then(res => {
              this.$message({
                type: "success",
                message: this.$t('common.tips.editSuccess')
              });
              this.dialogVisible = false;
              this.onSubmit();
            });
          }
        } else {
          setTimeout(() => {
            let isError = document.getElementsByClassName("is-error");
            if (isError[0] && isError[0] && isError[0].querySelector('input')) {
              isError[0].querySelector('input').focus();
            }
          }, 1);
        }
      });
    },
    reset() {
      this.queryForm.condition.templateName = '';
      this.queryForm.condition.trainingLevelList = [];
      this.queryForm.condition.trainingTypeList = [];
      this.queryForm.condition.degreeTypeList = ['2'];
      this.queryForm.condition.learnFormList = [];
      this.queryForm.condition.collegeAcademyList = "";
      this.queryForm.condition.majorList = [];
      this.options.majorList = [];
      this.queryForm.condition.isEnabled = '';
      this.onSubmit();
    },
    onSubmit() {
      this.queryForm.pageNum_ = 1;
      this.getListData();
    },
    getListData() {
      let params = JSON.parse(JSON.stringify(this.queryForm));
      params.condition.collegeAcademyList = !params.condition.collegeAcademyList ? [] : [params.condition.collegeAcademyList];
      graduateStudentApi.queryInternEvalList(params).then((res) => {
        if (res.code === 200) {
          this.dataList = res.data.list;
          this.queryForm.total_ = res.data.total_;
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 取消
    cancel() {
      let allIsEmpty = true;
      for (let key in this.dialogForm) {
        if ((!Array.isArray(this.dialogForm[key]) && (this.dialogForm[key] || this.dialogForm[key] === 0)) || (Array.isArray(this.dialogForm[key]) && this.dialogForm[key].length > 0) && key !== 'degreeTypeList') {
          allIsEmpty = false;
        }
      }
      let diffFlag = false;
      if (this.dialogMode === 'edit') {
        for (let key in this.editModeInfo) {
          if (Array.isArray(this.editModeInfo[key])) {
            let array1 = this.editModeInfo[key].sort().toString();
            let array2 = this.dialogForm[key].sort().toString();
            if (array1 !== array2) {
              diffFlag = true;
            }
          } else if (this.dialogForm[key] != this.editModeInfo[key]) {
            diffFlag = true;
          }
        }
      }
      if (allIsEmpty || (!diffFlag && this.dialogMode === 'edit')) {
        this.innerVisible = false;
        this.dialogVisible = false;
      } else {
        this.innerVisible = true;
      }
    },
    // 关闭x事件
    beforeClose: function (done) {
      this.cancel();
    },
    // 关闭弹框
    closeDialog() {
      this.dialogVisible = false;
    },
    // 内层确认框-确认
    confirmInner() {
      this.innerVisible = false;
      this.dialogVisible = false;
    },
    // 内层确认框-取消
    cancelInner() {
      this.innerVisible = false;
    },
    // 内层确认框-保存并取消
    confirmAndClose(formName) {
      this.innerVisible = false;
      this.save(formName);
    },
    // 新增实习评价模板
    addInternEvaluate() {
      this.title = this.$t('internEvaluateTempSet.internEvalTempMaintain');
      this.dialogMode = 'add';
      this.dialogVisible = true;
    },
    // 新增/编辑窗口修改学院
    changeDialogCollege(val) {
      this.options.profession = [];
      this.dialogForm.majorList = [];
      let params = [];
      if (val) {
        params = [val];
      }
      graduateStudentApi.getMajorByCollage(params).then(res => {
        if (res.code === 200) {
          if (Array.isArray(res.data) && res.data.length > 0) {
            // this.options.profession = val ? res.data : [...[{code: '', name: '全部'}], ...res.data];
            this.options.profession = val ? res.data : [];
          }
        }
      });
    },
    // 编辑实习评价模板
    async editInternEval(row) {
      this.title = this.$t('internEvaluateTempSet.internEvalTempMaintain');
      this.dialogMode = 'edit';
      let currentRow = JSON.parse(JSON.stringify(row));
      currentRow.trainingLevelList = currentRow.trainingLevelStr !== '全部' ? UTILS.translateMultiSelect(this.options.trainingLevelList, currentRow.trainingLevelStr, 'label', 'value') : ['全部'];
      currentRow.trainingTypeList = currentRow.trainingTypeStr !== '全部' ? UTILS.translateMultiSelect(this.options.trainingTypeList, currentRow.trainingTypeStr, 'label', 'value') : ['全部'];
      currentRow.degreeTypeList = UTILS.translateMultiSelect(this.options.degreeTypeList, currentRow.degreeTypeStr, 'label', 'value');
      currentRow.learnFormList = currentRow.learnFormStr !== '全部' ? UTILS.translateMultiSelect(this.options.learnFormList, currentRow.learnFormStr, 'label', 'value') : ['全部'];
      currentRow.collegeAcademyList = UTILS.translateMultiSelect(this.options.collegeAcademyList, currentRow.collegeAcademyStr, 'label', 'value')[0];
      // this.options.profession = [{
      //   code: '',
      //   name: '全部'
      // }];
      this.options.profession = [];
      const majorResult = await graduateStudentApi.getMajorByCollage([currentRow.collegeAcademyList]);
      if (majorResult.code === 200) {
        if (Array.isArray(majorResult.data) && majorResult.data.length > 0) {
          this.options.profession = majorResult.data;
          currentRow.majorList = currentRow.majorStr !== '全部' ? UTILS.translateMultiSelect(this.options.profession, currentRow.majorStr, 'name', 'code') : ['全部'];
        }
      }
      let targetRow = {};
      for (let key in this.dialogForm) {
        for (let keyRow in currentRow) {
          if (key === keyRow) {
            targetRow[key] = currentRow[keyRow];
          }
        }
      }
      this.editModeInfo = JSON.parse(JSON.stringify(targetRow));
      targetRow['id'] = currentRow.id;
      this.dialogForm = targetRow;
      // this.dialogForm['oldTemplateName'] = row.templateName;
      this.dialogVisible = true;
    },
    // 查看详情
    async selectDetails(row) {
      graduateStudentApi.queryInternEvalDetails(row.id).then(res => {
        this.dataListProp = res.data;
        this.indexMode = 'details';
        this.tableFlag = true;
      });
    },
    // 查看评价指标表
    selectEvalIndexTable(row) {
      graduateStudentApi.queryInternEvalIndexDetails(row.id).then(res => {
        this.dataListProp = res.data;
        this.indexMode = 'index';
        this.tableFlag = true;
      });
    },
    handleSizeChange(val) {
      this.queryForm.pageSize_ = val;
      this.getListData();
    },
    handleCurrentChange(val) {
      this.queryForm.pageNum_ = val;
      this.getListData();
    }
  },
  watch: {
    dialogVisible: {
      handler(newVal) {
        if (!newVal) {
          this.dialogForm = {
            "templateName": "",
            "trainingLevel": "",
            "trainingLevelList": [],
            "trainingType": "",
            "trainingTypeList": [],
            "degreeType": "",
            "degreeTypeList": [],
            "learnForm": "",
            "learnFormList": [],
            "collegeAcademy": "",
            "collegeAcademyList": "",
            "major": "",
            "majorList": [],
            "isEnabled": '',
            "description": ""
          }
          if (this.$refs['dialogForm']) {
            this.$refs['dialogForm'].resetFields();
          }
          this.dialogForm.degreeTypeList = ["2"];
        }
      },
      deep: true,
      immediate: true
    },
    auths: {
      handler(newVal) {
        if (newVal && Array.isArray(newVal) && newVal.length > 0) {
          newVal.some(item => {
            if (item.authCode === 'graduateStu-internEvalTemp-add') {
              this.permitToAdd = true;
            }
            if (item.authCode === 'graduateStu-internEvalTempSet-edit') {
              this.permitToEdit = true;
            }
            if (item.authCode === 'graduateStu-internEvalTempSet-details') {
              this.permitToDetail = true;
            }
            if (item.authCode === 'graduateStu-internEvalTempSet-selectTable') {
              this.permitToSelectTable = true;
            }
            if (item.authCode === 'graduateStu-internEvalTempSet-export') {
              this.permitToExport = true;
            }
          });
        }
      },
      deep: true,
      immediate: true
    }
  }
}
</script>
<style lang="scss" scoped>
  .condition-title {
    color: #2b3b4e;
    font-size: 18px;
    line-height: 24px;
    font-weight: bold;
  }
  .template-setting-dialog ::v-deep {
    .el-select {
      width: 100%!important;
    }
  }
  .is-enabled-container ::v-deep {
    .el-button {
      cursor: auto;
    }
    .el-button--danger {
      padding: 9px 15px;
      min-width: 0;
    }
  }
  .intern-eval-temp-set-container ::v-deep {
    .el-dialog__body {
      word-break: break-all!important;
    }
  }
</style>
